package com.yj.lcj.login.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yj.lcj.login.config.LoginConfig;
import com.yj.lcj.exception.ApiRespones;
import com.yj.lcj.login.pojo.AppUser;
import com.yj.lcj.respones.Result;
import com.yj.lcj.login.service.AppUserService;
import com.yj.lcj.utils.TokenManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Api(tags = "app登录接口")
@RestController
@RequestMapping("/app")
@Slf4j
public class AppLoginController {


    @Autowired
    private LoginConfig loginConfig;


    /**
     * 获取验证码
     * @param phone
     * @return
     * @throws ApiRespones
     */
    @ApiImplicitParams({@ApiImplicitParam(name = "phone",value = "手机号",required = true,dataType = "String")})
    @ApiOperation(value = "获取验证码",notes = "通过手机号获取验证码")
    @GetMapping("getCode")
    public Result getCode(String phone) throws ApiRespones{
       return loginConfig.getCode(phone);
    }

    /**
     * 手机号登陆
     * @param phone 手机号
     * @param code 验证码
     * @return
     * @throws ApiRespones
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone",value = "手机号",required = true,dataType = "String"),
            @ApiImplicitParam(name = "code",value = "验证码",required = true,dataType = "String")
    })
    @ApiOperation(value = "手机号登陆",notes = "手机号登陆")
    @GetMapping("/login")
    public Result login(String phone,String code,HttpServletRequest request) throws ApiRespones{
        Result login = loginConfig.login(phone, code,request);
        return login;
    }

    /**
     * 账号密码登陆
     * @param userName
     * @param password
     * @return
     * @throws ApiRespones
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userName",value = "用户名",required = true,dataType = "String"),
            @ApiImplicitParam(name = "password",value = "密码",required = true,dataType = "String")
    })
    @ApiOperation(value = "账号密码登陆",notes = "账号密码登陆")
    @GetMapping("/userLogin")
    public Result userLogin(String userName , String password) throws ApiRespones{
        Result result = loginConfig.userLogin(userName, password);
        return result;
    }

    /**
     * 注销
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId",value = "用户id",required = true,dataType = "int")
    })
    @ApiOperation(value = "注销",notes = "通过用户id进行注销（删除信息）")
    @GetMapping("/CancelOut")
    public Result CancelOut(@RequestParam("userId") int userId){
        loginConfig.CancelOut(userId);
        return new Result();
    }

    /**
     * 退出登陆
     * @param request
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token",value = "请求",required = true,dataType = "string")
    })
    @ApiOperation(value = "退出登陆",notes = "退出登陆")
    @GetMapping("layout")
    public Result layout(HttpServletRequest request) {
        Result layout = loginConfig.layout(request);
        return layout;
    }
}
